[[...routeSlug]].tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { NextPage } from 'next'
  2. import Head from 'next/head'
  3. import { useRouter } from 'next/router'
  4. import { cn } from 'ui'
  5. import {
  6. Header,
  7. LoadingCardView,
  8. NoOrganizationsState,
  9. } from '@/components/interfaces/Home/ProjectList/EmptyStates'
  10. import { buildOrgUrl } from '@/components/interfaces/Organization/Organization.utils'
  11. import { OrganizationCard } from '@/components/interfaces/Organization/OrganizationCard'
  12. import { PageLayout } from '@/components/layouts/PageLayout/PageLayout'
  13. import { ScaffoldContainer, ScaffoldSection } from '@/components/layouts/Scaffold'
  14. import { useOrganizationsQuery } from '@/data/organizations/organizations-query'
  15. import { useCustomContent } from '@/hooks/custom-content/useCustomContent'
  16. import { withAuth } from '@/hooks/misc/withAuth'
  17. import { buildStudioPageTitle } from '@/lib/page-title'
  18. const GenericOrganizationPage: NextPage = () => {
  19. const router = useRouter()
  20. const { appTitle } = useCustomContent(['app:title'])
  21. const { routeSlug, ...queryParams } = router.query
  22. const queryString =
  23. Object.keys(queryParams).length > 0
  24. ? new URLSearchParams(queryParams as Record<string, string>).toString()
  25. : ''
  26. const { data: organizations, isPending: isLoading } = useOrganizationsQuery()
  27. const pageTitle = buildStudioPageTitle({
  28. section: 'Select an organization',
  29. surface: 'Organizations',
  30. brand: appTitle || 'Briven',
  31. })
  32. return (
  33. <>
  34. <Head>
  35. <title>{pageTitle}</title>
  36. <meta name="description" content="Briven Studio" />
  37. </Head>
  38. <Header />
  39. <PageLayout className="grow min-h-0" title="Select an organization to continue">
  40. <ScaffoldContainer>
  41. <ScaffoldSection isFullWidth>
  42. <div
  43. className="grow overflow-y-auto"
  44. style={{ maxHeight: 'calc(100vh - 49px - 64px)' }}
  45. >
  46. <div className="w-full mx-auto flex flex-col gap-y-8">
  47. {isLoading ? (
  48. <LoadingCardView />
  49. ) : organizations?.length === 0 ? (
  50. <NoOrganizationsState />
  51. ) : (
  52. <ul
  53. className={cn(
  54. 'w-full mx-auto grid grid-cols-1 gap-4',
  55. 'sm:grid-cols-1 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3'
  56. )}
  57. >
  58. {organizations?.map((org) => (
  59. <OrganizationCard
  60. key={org.id}
  61. organization={org}
  62. href={buildOrgUrl({ slug: routeSlug, orgSlug: org.slug, queryString })}
  63. />
  64. ))}
  65. </ul>
  66. )}
  67. </div>
  68. </div>
  69. </ScaffoldSection>
  70. </ScaffoldContainer>
  71. </PageLayout>
  72. </>
  73. )
  74. }
  75. export default withAuth(GenericOrganizationPage)